home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / WASTE 1.2a4 / WASTE Demo / WEDemoAbout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  2.6 KB  |  142 lines  |  [TEXT/CWIE]

  1. /*
  2.     WASTE Demo Project:
  3.     About Boxes
  4.     
  5.     Copyright © 1993-1995 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11.  
  12. #ifndef __WEDEMOAPP__
  13. #include "WEDemoIntf.h"
  14. #endif
  15.  
  16. // some local stuff
  17.  
  18. #define    kItemTextPane    3
  19.  
  20. static UserItemUPP        sBoxPainter;
  21.  
  22. static pascal void DrawUserItem( DialogRef, short );
  23.  
  24.  
  25. OSErr    WETextBox( short textResID, const Rect *bounds, short alignment )
  26. {
  27.     WEReference        we = NULL;
  28.     LongRect        longBounds;
  29.     Handle            hText = NULL;
  30.     Handle            hStyles = NULL;
  31.     SignedByte        saveTextState, saveStylesState;
  32.     OSErr            err;
  33.     
  34.     // create a new WE instance
  35.     
  36.     WERectToLongRect( bounds, &longBounds );
  37.     err = WENew( &longBounds, &longBounds, 0, &we );
  38.     if ( err != noErr )
  39.         goto cleanup;
  40.     
  41.     // set the alignment style
  42.     
  43.     WESetAlignment( alignment, we );
  44.     
  45.     // load the styl resource and make it unpurgeable
  46.     
  47.     hStyles = GetResource( kTypeStyles, textResID );
  48.     err = ResError();
  49.     if ( err != noErr )
  50.         goto cleanup;
  51.     saveStylesState = HGetState( hStyles );
  52.     HNoPurge( hStyles );
  53.     
  54.     // load the text resource and lock it
  55.     
  56.     hText = GetResource( kTypeText, textResID );
  57.     err = ResError();
  58.     if ( err != noErr )
  59.         goto cleanup;
  60.     saveTextState = HGetState( hText );
  61.     HLockHi( hText );
  62.     
  63.     // insert the text
  64.     
  65.     err = WEInsert( *hText, GetHandleSize( hText ), (StScrpHandle)hStyles, NULL, we );
  66.     if ( err != noErr )
  67.         goto cleanup;
  68.     
  69.     // clear the result code
  70.     
  71.     err = noErr;
  72.     
  73.     // cleanup
  74.     
  75. cleanup:
  76.  
  77.     if ( hText != NULL )
  78.         HSetState( hText, saveTextState );
  79.     
  80.     if ( hStyles != NULL )
  81.         HSetState( hStyles, saveStylesState );
  82.     
  83.     WEDispose( we );
  84.     
  85.     // return the result code
  86.     
  87.     return err;
  88. }
  89.  
  90. pascal void    DrawUserItem( DialogRef dialog, short item )
  91. {
  92.     Rect        r;
  93.     
  94.     // draw the text, centered, in the item rect
  95.  
  96.     GetDialogItemRect( dialog, item, &r );
  97.     
  98.     if ( WETextBox( GetWRefCon(GetDialogWindow(dialog)), &r, weCenter) != noErr )
  99.         ; // insert error handling here
  100.     
  101.     return;
  102. }
  103.  
  104.  
  105. void    DoAboutBox( short dialogID )
  106. {
  107.     DialogRef        aboutBox;
  108.     short            itemHit;
  109.     
  110.     // get the about box
  111.     
  112.     aboutBox = GetNewDialog( dialogID, NULL, (WindowRef)-1L );
  113.     if ( aboutBox == NULL )
  114.         return;
  115.     
  116.     // install a user item drawing procedure for the text pane
  117.     
  118.     if ( sBoxPainter == NULL )
  119.         sBoxPainter = NewUserItemProc( DrawUserItem );
  120.     SetDialogItemProc( aboutBox, kItemTextPane, sBoxPainter );
  121.  
  122.     // store ID of TEXT/styl pair (= ID of dialog template) in dialog refCon
  123.     
  124.     SetWRefCon( GetDialogWindow(aboutBox), dialogID );
  125.     
  126.     // put up the dialog
  127.     
  128.     SetCursor( &qd.arrow );
  129.     
  130.     ShowWindow( GetDialogWindow(aboutBox) );
  131.     SetGrafPortOfDialog(aboutBox);
  132.     
  133.     // wait for a click
  134.     
  135.     ModalDialog( GetMyStandardDialogFilter(), &itemHit );
  136.     
  137.     // bring down the dialog
  138.     
  139.     DisposeDialog( aboutBox );
  140.     
  141.     return;
  142. }